
package com.ncjk.utcs;

/**
 * Please modify this class to meet your needs
 * This class is not complete
 */

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;

import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;

/**
 * This class was generated by Apache CXF 2.7.18
 * 2016-12-30T13:30:08.050+08:00
 * Generated source version: 2.7.18
 * 
 */
public final class UtcsJkService_UtcsJkServiceImplPort_Client {

    private static final QName SERVICE_NAME = new QName("http://utcs.ncjk.com/", "UtcsJkService");

    private UtcsJkService_UtcsJkServiceImplPort_Client() {
    }

    public static void main(String args[]) throws java.lang.Exception {
        URL wsdlURL = UtcsJkService_Service.WSDL_LOCATION;
        if (args.length > 0 && args[0] != null && !"".equals(args[0])) { 
            File wsdlFile = new File(args[0]);
            try {
                if (wsdlFile.exists()) {
                    wsdlURL = wsdlFile.toURI().toURL();
                } else {
                    wsdlURL = new URL(args[0]);
                }
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
        }
      
        UtcsJkService_Service ss = new UtcsJkService_Service(wsdlURL, SERVICE_NAME);
        UtcsJkService port = ss.getUtcsJkServiceImplPort();  
        
        {
        System.out.println("Invoking utcsCommand...");
        java.lang.String _utcsCommand_command = createSysInfo();
            System.out.println(_utcsCommand_command);
        java.lang.String _utcsCommand__return = port.utcsCommand(_utcsCommand_command);
        System.out.println("utcsCommand.result=" + _utcsCommand__return);


        }

        System.exit(0);
    }

    private static String createSysInfo(){
        try {
            Document document = DocumentHelper.parseText(createHeader());
            Element operation = document.getRootElement().element("Body").addElement("Operation");
            operation.addAttribute("Order","1");
            operation.addAttribute("name","Get");
            Element tscCmd = operation.addElement("TSCCmd");
            tscCmd.addElement("ObjName").setText("CrossControlMode");
            tscCmd.addElement("ID").setText("36012200000012");
            tscCmd.addElement("No");
          /* Element lockFlowDirection = operation.addElement("UnLockFlowDirection");
            lockFlowDirection.addElement("CrossID").setText("36012200000012");
            lockFlowDirection.addElement("Type").setText("0");
            lockFlowDirection.addElement("Entrance").setText("0");
            lockFlowDirection.addElement("Exit").setText("0");*/
           /* Element crossPlan = operation.addElement("CrossPlan");
            crossPlan.addElement("CrossID").setText("");
            crossPlan.addElement("PlanNo").setText("1");*/
           /* lockFlowDirection.addElement("StartTime").setText("0");
            lockFlowDirection.addElement("Duration").setText("0");*/
            return outPut(document);
        } catch (DocumentException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static String createHeader() {
        Document document = DocumentHelper.createDocument();
        Element message = document.addElement("Message");
        message.addElement("Version").setText("1.0");
        message.addElement("Token").setText("1234");
        Element from = message.addElement("From");
        Element fromAddress = from.addElement("Address");
        fromAddress.addElement("Sys").setText("TICP");
        fromAddress.addElement("SubSys");
        fromAddress.addElement("Instance");
        Element to = message.addElement("To");
        Element toAddress = to.addElement("Address");
        toAddress.addElement("Sys").setText("UTCS");
        toAddress.addElement("SubSys");
        toAddress.addElement("Instance");
        message.addElement("Type").setText("REQUEST");
        message.addElement("Seq").setText("20170224150318000001");
        message.addElement("Body");
        return outPut(document);
    }

    public static String outPut(Document document) {
        OutputFormat format = OutputFormat.createCompactFormat();
       /* format.setIndent(true); //设置是否缩进
        format.setIndent("   "); //以空格方式实现缩进
        format.setNewlines(true); //设置是否换行*/
        StringWriter writer = new StringWriter();
        XMLWriter output = new XMLWriter(writer,format);
        try {
            output.write(document);
            writer.close();
            output.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return writer.toString();
    }
}
